package com.zy.interceptor;

import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author LittleDesire
 * @description
 * @date 2022-04-07 周四 17:15
 * @since 17
 */
public class MyInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("pre");


        if (handler instanceof HandlerMethod handlerMethod) {
            System.out.println("当前拦截的方法为：" + handlerMethod.getMethod().getName());
            System.out.println("当前拦截的方法参数长度为：" + handlerMethod.getMethod().getTypeParameters().length);
            System.out.println("当前拦截的方法的类名为：" + handlerMethod.getBean().getClass().getName());
            System.out.println("拦截的URI为： "+request.getRequestURI());
        }


        return HandlerInterceptor.super.preHandle(request, response, handler);
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("psot");
        HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("after");
        HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
    }
}
